package com.leyou.auth.config;

import com.leyou.auth.task.PrivileageAuthTokenHolder;
import com.leyou.common.auth.JwtUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author xiuer
 * @description 自定义拦截器
 * @create 2019/7/11 15:16
 */
public class PrivilegeTokenConfig implements RequestInterceptor {

    private JwtProperties properties;
    private PrivileageAuthTokenHolder tokenHolder;

    public PrivilegeTokenConfig(JwtProperties properties, PrivileageAuthTokenHolder tokenHolder) {
        this.properties = properties;
        this.tokenHolder = tokenHolder;
    }

    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(properties.getPrivilege().getHeaderName(), tokenHolder.getToken());
    }
}
